import IScript from "../IScript";
import {user} from "../../types/msg"
import Player from "../../Player";
import ObjContainer from "../../ObjContainer";

export  class S2C_AddPlayerScript implements IScript {

    private static  _instance = new S2C_AddPlayerScript()
    public static get instance(){
        return S2C_AddPlayerScript._instance;
    }
    private constructor(){}

    excute(obj: any) {
        this.handle(obj )
    }

    handle(msg: user.S2C_AddPlayer) {
        if(!msg.newPlayer) return
        let newPlayer = msg.newPlayer
        let player = new Player(newPlayer.id as string,false);
        player.x = newPlayer.x as number
        player.y = newPlayer.y as number
        ObjContainer.addObj(player)
    }
}

export default S2C_AddPlayerScript.instance
